package cn.admin.service.impl;

import cn.admin.dao.PowerMapper;
import cn.admin.entity.Power;
import cn.admin.service.PowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 12:38 2019/3/24
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PowerServiceImpl implements PowerService {


    @Autowired private PowerMapper powerMapper;


    @Override
    public List<Power> getPower(int adminId) {
        return powerMapper.findPower(adminId);
    }

    @Override
    public boolean addPower(List<Power> power) {
        boolean flag=false;
        for (Power p : power) {
            //遍历插入
            int i = powerMapper.insertPower(p);
            //失败则停止插入
            if (i>0){
                flag=true;
            }else{
                flag=false;
                break;
            }
        }
        return flag;
    }
}
